package com.wu.weiyang.controller;

import com.wu.weiyang.bean.PushMessageBean;
import com.wu.weiyang.controller.websocket.NoticeService;
import com.wu.weiyang.util.CreateResponse;
import com.wu.weiyang.util.ResponseTemp;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * className: ReturnMessage <br/>
 * author: 50816 <br/>
 * date: 2019/8/19 21:02 <br/>
 * describe:
 */
@RestController
@RequestMapping("/ws")
public class ReturnMessage {

    @PostMapping("/push")
    public ResponseTemp pushMsg(@RequestBody PushMessageBean msg) {
        try {
            NoticeService.refowd(msg.toString(), msg.getToId());
        } catch (IOException e) {
            e.printStackTrace();
            return CreateResponse.fail("消息发送失败");
        }
        return CreateResponse.success("消息发送成功");
    }
}
